#include "DotDetection.h"


DotDetection::DotDetection(void) : Filter(1, 1)
{
	outputs[0] = cv::Mat(1, 4, CV_32SC1);
}


DotDetection::~DotDetection(void)
{
}

void DotDetection::Process()
{
	//find brightest point on screen

	int maxVal = -1;
	cv::Point point(-1, -1);

	for (int j = 0; j < inputs[0]->rows; ++j)
	{
		cv::Vec3b *p = inputs[0]->ptr<cv::Vec3b>(j);
		for (int i = 0; i < inputs[0]->cols; ++i)
		{
			int val = p[i][0] + p[i][1] + p[i][2];
			if (val > maxVal)
			{
				maxVal = val;
				point = cv::Point(i, j);
				if (maxVal == 3 * 255)
					break;
			}
		}
		if (maxVal == 3 * 255)
			break;
	}

	outputs[0].at<int>(0, 0) = point.x - 2;
	outputs[0].at<int>(0, 1) = point.y - 2;
	outputs[0].at<int>(0, 2) = 4;
	outputs[0].at<int>(0, 3) = 4;
}